<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //1.新增数组元素 通过修改length长度
        var arr = ['red', 'blue', 'green'];
        console.log(arr.length);
        arr.length = 5; //把数组的长度修改为了 5 .里面应该有5 个元素
        console.log(arr);
        console.log(arr[3]); //undefined

        //2.新增数组元素 修改索引号 追加数组元素
        var arr1 = ['red', 'blue', 'green'];
        arr1[3] = 'pink';
        console.log(arr1);
        arr1[0] = 'yellow'; //在原有基础上修改会替换数组元素
        arr1 = 'asd';
        console.log(arr1); //不要直接给数组赋值
    </script>
</head>

<body>

</body>

</html>